package com.xjj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.xjj.entity.PageBean;
import com.xjj.entity.School;
import com.xjj.entity.Student;
import com.xjj.mapper.StudentMapper;
import com.xjj.service.StudentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sxy
 * @version 1.0
 * @date 2022/10/20 14:11
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {
    @Resource
    private StudentMapper studentMapper;

    @Override
    public Page<Student> getStudent(Integer current) {
        Page<Student> page = new Page<>(current, 10);
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("*");
        page = studentMapper.selectPage(page, queryWrapper);
        return page;
    }

    @Override
    public void updateStudentById(Student student) {
        studentMapper.updateStudentById(student);
    }

    // 多条件分页
    @Override
    public PageBean<Student> getByPage(Student student, Integer pageNum, Integer pageSize) {
        PageBean<Student> pageBean = new PageBean<>();
        com.github.pagehelper.Page page = PageHelper.startPage(pageNum, pageSize);
        List<Student> goodsList = studentMapper.getByCondition(student);

        pageBean.setCurrPage(pageNum);
        pageBean.setData(goodsList);
        pageBean.setCurrPageSize(goodsList.size());
        pageBean.setPageSize(pageSize);
        pageBean.setTotalPages(page.getPages());
        pageBean.setTotalNums((int) page.getTotal());
        return pageBean;
    }

    @Override
    public List<Student> getAllStudentsByKlassId(int klassId) {
        return studentMapper.getAllStudentsByKlassId(klassId);

    }

    @Override
    public List<Student> getByTel(String tel) {
        return studentMapper.getByTel(tel);
    }

    @Override
    public void addSubmitNumById(int id) {
        studentMapper.addSubmitNumById(id);
    }

    @Override
    public void updateByCondition(Student student) {
        if (student.getId() == null) {
            throw new NullPointerException("id不能为空");
        }
        studentMapper.updateByCondition(student);
    }

    @Override
    public void decreaseSubmitNumById(int id) {
        studentMapper.decreaseSubmitNumById(id);
    }

    @Override
    public List<Student> getAllStudentsByKlassId1(int klassId) {
        return studentMapper.getAllStudentsByKlassId1(klassId);
    }

    @Override
    public School getSchoolBySchoolId(int schoolId) {
        return studentMapper.getSchoolBySchoolId(schoolId);
    }

    @Override
    public List<Student> findAllStudent() {
        return studentMapper.findAllStudent();
    }

    @Override
    public List<Student> getByCondition(Student student) {
        return studentMapper.getByCondition(student);
    }

}
